package com.like.example.adapters;

import com.like.LikeButton;
import com.like.example.ResourceTable;
import ohos.agp.components.Text;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.BaseItemProvider;
import ohos.app.Context;

public class ListAdapter extends BaseItemProvider {
    private final Context context;

    public ListAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        int max = 30;
        return max;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    /**
     * @noinspection checkstyle:NeedBraces
     */
    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        Component item = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_list_row, componentContainer, false);
        Text title = (Text) item.findComponentById(ResourceTable.Id_title);
        LikeButton starButton = (LikeButton) item.findComponentById(ResourceTable.Id_star_button);
        title.setText(String.valueOf(i));
        starButton.setLiked(i % 2 == 0);
        return item;
    }
}
